function compose(...fns) {
    return function (...args) {
        return fns.reduce(function (preItem, curFn, index) {
            if (index === 0) {
                return curFn(...preItem);
            }
            return curFn(preItem);
        }, args);
    };
}

function composeRight(...fns) {
    return function (...args) {
        var len = fns.length;
        return fns.reduceRight(function (preItem, curFn, index) {
            if (index === len - 1) {
                return curFn(...preItem);
            }
            return curFn(preItem);
        }, args);
    };
}

var toLower = function (str) {
    return str.toLowerCase();
};

var subStr = function (str) {
    return str.substr(5);
};

var addStr = function (str) {
    return 'xxx-' + str;
}

var composedFun = compose(subStr, addStr, toLower);
// var composedFun = composeRight(toLower, addStr, subStr);

var res = composedFun('FIFISISDDJFIFDAfjdjsjjs');
console.log(res);
